package pub.cleangao.common.unique;

public class Ip2Integer {

    public static int ipToInt(String ip) {
        String[] parts = ip.split("\\.");
        int result = 0;
        for (int i = 0; i < parts.length; i++) {
            result |= Integer.parseInt(parts[i]) << (8 * (3 - i));
        }
        return result;
    }

    public static String intToIp(int ip) {
        return ((ip >> 24) & 0xFF) + "." +
                ((ip >> 16) & 0xFF) + "." +
                ((ip >> 8) & 0xFF) + "." +
                (ip & 0xFF);
    }

}
